<!--结清-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="car-label">关键字:</div>
      <el-input v-model="listQuery.keyString" placeholder="姓名/手机号/身份证号" style="width: 180px;" class="filter-item" />
      <div class="car-label">贷款银行:</div>
      <el-select v-model="listQuery.bank" style="width: 140px" class="filter-item">
        <el-option v-for="item in banks" :key="item.id" :label="item.bankName" :value="item.id" />
      </el-select><div class="car-label">状态:</div>
     <el-select v-model="listQuery.status" style="width: 140px" class="filter-item">
       <el-option v-for="item in statuses" :key="item.key" :label="item.label" :value="item.key" />
     </el-select>
      <div class="car-label">结清方式:</div>
      <el-select v-model="listQuery.closedType" style="width: 140px" class="filter-item">
        <el-option v-for="item in types" :key="item.key" :label="item.label" :value="item.key" />
      </el-select>
      <el-button v-waves style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search" @click="search">
        搜索
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item right-btn" type="primary" @click="handleSettle">
        结清
      </el-button>
    </div>
    <ve-table
      style="width:100%"
      :columns="columns"
      :table-data="tableData"
      :border-x="true"
      row-key-field-name="id"
      :border-y="true"
      :row-style-option="rowStyleOption"
      :checkbox-option="checkboxOptipon"
    />
    <div class="table-pagination">
      <ve-pagination
        :total="totalCount"
        :page-index="pageIndex"
        :page-size="pageSize"
        @on-page-number-change="pageNumberChange"
        @on-page-size-change="pageSizeChange"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
</style>

<script>

export default {
  data() {
    return {
      // page index
      tableData: [],
      totalCount: '',
      dialogTitle: '新增经销商', // 弹框名称
      editorFlag: false,
      newDialog: false, // 添加弹框
      formData: {}, // 添加表单
      appId:"",
      pageIndex: 1,
      pageSize: 10,
      listQuery: {},
      selectedRowKeys:{},
      banks:[],
      statuses:[{key:0,label:"待结清"},{key:1,label:"已结清"}],
      types:[{key:0,label:"正在结清"},{key:1,label:"代偿结清"},{key:2,label:"提前结清"}],
      rowStyleOption: { // 表格样式
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          if(isSelected){
            this.selectedRowKeys = selectedRowKeys;
          }
          console.log(row, isSelected, selectedRowKeys)
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: 'f',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          }
        },
        { field: 'orderId', key: 'b', title: '订单编号', align: 'center', width: '100px' },
        { field: 'mainUser', key: 'c', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'loanAmount', key: 'd', title: '贷款金额', width: '' },
        { field: 'status', key: 'g', title: '状态', width: '' },
        { field: 'department', key: 'e', title: '部门', width: '' },
        { field: 'serviceUser', key: 'f', title: '业务员', width: '' },
        { field: 'bank', key: 'l', title: '贷款银行', width: '' },
        { field: 'closedType', key: 'n', title: '结清方式', width: '' }
      ]
    }
  },
  computed: {
  },
  created() {
    this.appId = sessionStorage.getItem("appId");
    this.initDatabase();
    this.getBankList();
  },
  methods: {
    search(){
      this.pageIndex = 1;
      this.initDatabase();
    },
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
      this.initDatabase();
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.initDatabase();
    },

    /**
       * 获取银行列表数据
       * @date 2021-05-18
       */
      async getBankList () {
        let param = {appId: await sessionStorage.getItem("appId")};
        let data = await this.$http.post('/auth/bankSetup/listAll', param);
        if (data.code === 200) {
          this.banks = data.data;
        }
      },
    /**
     * 初始化数据
     * @date 2021-05-10
     */
    async initDatabase() {
      this.tableData = [];
      this.listQuery.appid = this.appId;

      let data = await this.$http.post('/flow/closed/list/'+ this.pageIndex + "/" + this.pageSize, this.listQuery)
      console.log(data);
      if (data.code === 200) {
        this.tableData = data.data.records;
        this.totalCount = data.data.total;
      } else {
      this.$message({
        type: 'error',
        message: '查询失败，请刷新页面'
      });
      }

      console.log(this.tableData)
    },
    //点击跳转到结算详情页面
    handleSettle(){
      this.$router.push({ path: '/a-content/manager/settle-manager/settle-detail', query: { id: this.selectedRowKeys}})
    }

  }
}
</script>
